#include <cstdio>
#include <map>
#include <functional>
#include <exception>
#include <string.h>
using namespace std;

class BaseNode
{
public:
	virtual ~BaseNode() {}

	BaseNode* left;
	BaseNode* right;

	BaseNode()
	{
		left = right = NULL;
	}
};

struct OperatorNode : public BaseNode
{
	static std::function<double( double, double)> binops[256];
	
	char op;
	OperatorNode( char _op ): op( _op )
	{
	}
};

std::function<double( double, double)> OperatorNode::binops[];

struct ValueNode : public BaseNode
{
	double value;
	ValueNode( double _value ): value( _value )
	{
	}
};

struct FormatErrorException : public exception
{
};

struct ValueErrorException : public exception
{
};

void BuildExpTree( const char* exp_begin, const char* exp_end, BaseNode** ppNode )
{
	while( *exp_begin == ' ') exp_begin++;
	while( *(exp_end - 1) == ' ' ) exp_end--;

	if( exp_begin >= exp_end )
	{
		throw FormatErrorException();
	}

	int level = 0;
	const char* p1 = 0; //Position of rightmost operator
	for( const char* p = exp_begin; p != exp_end; p++ )
	{
		switch( *p )
		{
		case '(': level++; break;
		case ')': level--; break;
		}
		
		if( !level && NULL != OperatorNode::binops[ (int)*p ] )
		{
			p1 = p;
		}
	}

	BaseNode* pNode = NULL;

	if( p1 )
	{
		pNode = new OperatorNode( *p1 );
		BuildExpTree( exp_begin, p1, &pNode->left );
		BuildExpTree( p1 + 1, exp_end, &pNode->right );
	}
	else
	{
		if( *exp_begin == '(' || *(exp_end - 1) == ')' )
		{
			if( *exp_begin == '(' && *(exp_end - 1) == ')' )
			{
				BuildExpTree( exp_begin + 1, exp_end - 1, &pNode );
			}
			else
			{
				throw FormatErrorException();
			}
		}
		else
		{
			double value = 0.0;
			sscanf( exp_begin, "%lf", &value );
			pNode = new ValueNode( value );
		}
	}

	*ppNode = pNode;
}

double EvaluateExpTree( BaseNode* pNode )
{
	OperatorNode* pOpNode = dynamic_cast<OperatorNode*>( pNode );
	ValueNode* pVNode = dynamic_cast<ValueNode*>( pNode );

	if( pVNode )
	{
		return pVNode->value;
	}

	if( pOpNode )
	{
		double valuel = EvaluateExpTree( pOpNode->left );
		double valuer = EvaluateExpTree( pOpNode->right );

		if( OperatorNode::binops[ (int)pOpNode->op ] == NULL )
		{
			throw FormatErrorException();
		}
		
		return OperatorNode::binops[ (int)pOpNode->op ]( valuel, valuer );
	}

	throw FormatErrorException();
}

int main()
{
	OperatorNode::binops['+'] = plus<double>();
	OperatorNode::binops['-'] = minus<double>();
	OperatorNode::binops['*'] = multiplies<double>();
	OperatorNode::binops['/'] = divides<double>();
	OperatorNode::binops['%'] = modulus<int>();

	char exp[512] = {0};
	gets( exp );
	//exp: a * b + c * d
	
	

	BaseNode* pNode = NULL;
	try
	{
		BuildExpTree( exp, exp + strlen( exp ), &pNode );
		printf( "The value is %f\n", EvaluateExpTree( pNode ) );
	}
	catch( FormatErrorException& )
	{
		printf( "The format of expression is error!\n" );
	}
	catch( ValueErrorException& )
	{
		printf( "The value of expression is error!\n" );
	}


	return 0;
}